package com.wss.controller;


import com.alibaba.fastjson.JSONObject;
import com.wss.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;


    @PostMapping("/admin/login/status")
    public Object loginStatus(HttpServletRequest request, HttpSession session){
        JSONObject jsonObject = new JSONObject();

        String name = request.getParameter("name");
        String password = request.getParameter("password");

        boolean res = adminService.veritypasswd(name,password);

        if(res){
            jsonObject.put("code",1);
            jsonObject.put("msg","登陆成功");
            session.setAttribute("name",name);
            return jsonObject;
        }else{
            jsonObject.put("code",0);
            jsonObject.put("msg","用户名或密码错误");
            return jsonObject;
        }
    }
}
